package com.magnificent.atlantis.common.user;

import com.magnificent.atlantis.common.entity.ServerUser;
import com.magnificent.commons.utils.settings.JAXBUtils;

import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.List;

/**
 * User: Babanin
 * Date: 13.08.2009
 * Time: 21:49:01
 */
@XmlRootElement(name = "serverDescriptor")
public class ServerDescriptor {

    private static final Class[] CLASSES = new Class[]{ServerDescriptor.class, ServerUser.class};

    private String host;
    private int port;

    private List<ServerUser> userList;

    public ServerDescriptor() {
    }

    @XmlAttribute()
    public String getHost() {
        return host;
    }

    public void setHost(String host) {
        this.host = host;
    }

    @XmlAttribute()
    public int getPort() {
        return port;
    }

    public void setPort(int port) {
        this.port = port;
    }

    @XmlElement()
    public List<ServerUser> getUserList() {
        return userList;
    }

    public void setUserList(List<ServerUser> userList) {
        this.userList = userList;
    }

    public static void save(String path, ServerDescriptor serverDescriptor) {
        JAXBUtils.saveSettings(path, CLASSES, serverDescriptor);
    }

    public static ServerDescriptor load(String path) {
        return (ServerDescriptor) JAXBUtils.loadSettings(path, CLASSES);
    }
}
